home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
576-600
/
592
/
star
/
star.doc
< prev
next >
Wrap
Text File
|
1995-03-15
|
6KB
|
171 lines
STAR V1.0
---------
By Jason Lowe
(December 1991)
PREFACE:
Completed: December, 1991
Language: Aztec C and Lattice C.
Programmer: Jason Lowe
Age: 18
Computer: Amiga 500
Comments: Works fine with both Aztec and Lattice.
Any questions, ideas, comments etc on anything to do with me or my code
please write. My home address is
5 Collaroy Close
Chittaway Bay
N.S.W 2259
Australia.
Star is not a stand alone graphics demonstration for the Amiga. It is a
few C functions that can be accessed very easily by any C programmer. This
program and its code is distributed as NO RIGHTS RESERVED. You may modify
this program to fit your own needs, and use it where ever you wish. The
following text file explains,
(a) How the program actually draws stars.
(b) How to use these C functions in your own programs.
(c) Conclusion.
(a) How the program actually draws stars.
This program uses no fancy mathematics to draw its stars. The following
is the basic idea behind drawing the stars.
Firstly to demonstrate how star works, go and grab a pen and paper. On
this piece of paper draw a reletively neat circle. On the circumference of
this circle mark 8 points such that they are all equally spaced. Then
number these points in a clockwise direction 1,2,3,4,5,6,7 and 8. Now we
are ready to draw our star.
Start at point 1 and count 3 points around the circle in a clockwise
direction. You should have ended up at point 4. Now join these two points
together.
Now from point 4 do exactly the same thing. Count 3 points around the
circle in a clockwise direction. You should have ended up at point 7. Now
connect these two points. Repeat this process until you end up back at
point 1. As you can guess the whole process will start over again.
As you can see when you have finished you have a shape which looks
something like a star. This is the process I have used in drawing my stars.
Open the program STAR, which opens up a HIRES INTERLACED screen and draws
stars randomly. If there is no code for any of the programs I have written,
just write to me and I would be more than happy to send it to you.
(b) How to use these C functions in your own programs.
There are 3 functions which you use in your own program to create stars.
These 3 functions work in a similar way to the way you drew a star on a piece
of paper. The 3 functions that you use are,
i) Init_Values
ii) Draw_Star
iii) Free_Values
Now I will use an example program to illustrate the use of each of these
functions.
LINE 1: #include "star.h"
LINE 2: main()
LINE 3: {
LINE 4: int *values1;
LINE 5: values1=Init_Values(50,8);
LINE 6: if(values1==0) exit(0); /* Can't allocate memory for stars */
LINE 7: Draw_Star(rastport,values1,120,120,3);
LINE 8: Free_Values(values1);
LINE 9: }
Firstly you must include star.h in your porgram. You must also to
remember to compile and link your program which your mathematical
libraries, due to this program using floating point. (Only once).
After you have included star.h you need to declare an integer pointer. In
the example above I have declared values1 as an integer pointer. Then you
must call the function Init_Values. If Init_Values has done its job
correctly it will return a normal integer pointer, else if something went
wrong it will return 0. You can call this function as many times as you
wish. (Just remember to use different integer pointers).
Synopsis: pointer=Init_Values(radius,points)
pointer: pointer is an integer pointer that you declare yourself.
Returns 0 if something went wrong.
radius: (int) This is the radius of the circle that your star is
going to be drawn in. (In pixels).
points: (int) This is how many points the computer will calculate
around the circle.
As you can remember from before you drew a circle of a given radius then
calculated a certain number of points around it. This is what this function
does. In the example above I have asked for 8 equally spaced points around
a circle of radius 50 pixels. (Just like our example on paper). Now to get
the computer to actually draw stars from these points we must call Draw_Star.
Synopsis: Draw_Star(rastport,pointer,X,Y,count)
rastport: (Struct Rastport *) This is a pointer to the rastport you
wish to draw the star in.
pointer: (int *) This is the integer pointer that was returned by
Init_Values.
X: (int) This is the x co-ordinate of the center of the star.
Y: (int) This is the y co-ordinate of the center of the star.
count: (int) This is how many points you wish to jump at a time. In
the star you drew on paper, you used 3.
In the example above I have selected to draw a star at location
(120,120) and jump 3 points a time, just like in the example we drew on
paper. You may also call this function as many times as you wish.
Now once you have finished drawing stars, you must deallocate all memory
allocated. You do this with the function Free_Values.
Synopsis: Free_Values(pointer)
pointer: (int *) This is the integer pointer that was returned by
Init_Values.
(c) Conclusion.
This program can get rather tedious after a while, but never the less it
would still look quite attractive in a larger demo you are writing. If you
have the time why not try to write something similar to this and send it to
me. I would be very interested to see it. I would also send you some of my
latest ideas and code.
I have just recently joined Anders Bjerin's C club. It is a very
worthwhile cause for all you buddying C programmers out there. If you
haven't checked out Anders' C manual do so, and you'll learn heaps from it!
In the mean time....
*** HAPPY PROGRAMMING ***